package com.ruoyi.web.cp.service.cp;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.web.cp.domain.rm.CpAo5;
import com.ruoyi.web.cp.service.WinxinService;
import com.ruoyi.web.mapper.CpAo5Mapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class Ao53Service {
    @Autowired
    private CpAo5Mapper cpAo5Mapper;
    @Autowired
    private WinxinService winxinService;
    private static final String[][] indexs = new String[][]{
            {"preDrawCode1", "preDrawCode2"},
            {"preDrawCode1", "preDrawCode3"},
            {"preDrawCode1", "preDrawCode4"},
            {"preDrawCode1", "preDrawCode5"},
            {"preDrawCode2", "preDrawCode3"},
            {"preDrawCode2", "preDrawCode4"},
            {"preDrawCode2", "preDrawCode5"},
            {"preDrawCode3", "preDrawCode4"},
            {"preDrawCode3", "preDrawCode5"},
            {"preDrawCode4", "preDrawCode5"},
    };

    public void execute(String wxKey) {
        List<CpAo5> cpAo5s = cpAo5Mapper.selectTop5(null);
        CpAo5 ao50 = cpAo5s.get(0);
        CpAo5 ao51 = cpAo5s.get(1);
        CpAo5 ao52 = cpAo5s.get(2);
        for (int j = 0; j < indexs.length; j++) {
            String code01 = ao50.getPreDrawCodeByIndex(indexs[j][0]);
            String code02 = ao50.getPreDrawCodeByIndex(indexs[j][1]);
            String code11 = ao51.getPreDrawCodeByIndex(indexs[j][0]);
            String code12 = ao51.getPreDrawCodeByIndex(indexs[j][1]);
            String code21 = ao52.getPreDrawCodeByIndex(indexs[j][0]);
            String code22 = ao52.getPreDrawCodeByIndex(indexs[j][1]);
            boolean boo1 = code01.equals(code11);
            boolean boo2 = code02.equals(code12);
            boolean boo3 = code01.equals(code21);
            boolean boo4 = code02.equals(code22);
            if (code11.equals(code12)) {
                if ((boo1 && boo2) || (boo3 && boo4)) {
                    String msg = StrUtil.format("{}\n" +
                                    "本期:{}\n" +
                                    "上期:{}\n" +
                                    "上上期:{}\n" +
                                    "{},{}\n",
                            ao50.getPreDrawIssue(),
                            ao50.getPreDrawCode(),
                            ao51.getPreDrawCode(),
                            ao52.getPreDrawCode(),
                            indexs[j][0], indexs[j][1]);
                    winxinService.sendQlMsg(wxKey, msg);
                }
            }
            if (code01.equals(code02) && (boo1 || boo2)) {
                String msg = StrUtil.format("{}\n" +
                                "本期:{}\n" +
                                "上期:{}\n" +
                                "上上期:{}\n" +
                                "{},{}\n",
                        ao50.getPreDrawIssue(),
                        ao50.getPreDrawCode(),
                        ao51.getPreDrawCode(),
                        ao52.getPreDrawCode(),
                        indexs[j][0], indexs[j][1]);
                winxinService.sendQlMsg("fbb32c0c-39d1-4e9e-9209-b4be4c7d234e", msg);
            }
        }
    }
}
